package com.example.emoji.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.emoji.R;
import com.example.emoji.bean.Emojicon;
import com.example.emoji.ui.EmojiconTextView;

import java.util.List;

public class EmojiconAdapter extends ArrayAdapter<Emojicon> {
    private boolean mUseSystemDefault = false;

    public EmojiconAdapter(Context context, List<Emojicon> data) {
        super(context, R.layout.emojicon_item, data);
        mUseSystemDefault = false;
    }

    public EmojiconAdapter(Context context, List<Emojicon> data, boolean useSystemDefault) {
        super(context, R.layout.emojicon_item, data);
        mUseSystemDefault = useSystemDefault;
    }

    public EmojiconAdapter(Context context, Emojicon[] data) {
        super(context, R.layout.emojicon_item, data);
        mUseSystemDefault = false;
    }

    public EmojiconAdapter(Context context, Emojicon[] data, boolean useSystemDefault) {
        super(context, R.layout.emojicon_item, data);
        mUseSystemDefault = useSystemDefault;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = convertView;
        if(view==null){
            view = View.inflate(getContext(), R.layout.emojicon_item,null);
            ViewHolder viewHolder = new ViewHolder();
            viewHolder.icon = (EmojiconTextView) view.findViewById(R.id.emojicon_icon);
            viewHolder.icon.setUseSystemDefault(mUseSystemDefault);
            view.setTag(viewHolder);
        }
        Emojicon emojicon = getItem(position);
        ViewHolder viewHolder = (ViewHolder) view.getTag();
        viewHolder.icon.setText(emojicon.getEmoji());
        return view;
    }

    static class ViewHolder {
        EmojiconTextView icon;
    }
}
